package mybatis.main;

import static java.lang.System.out;

import java.io.Reader;
import java.util.Arrays;

import mybatis.domain.Search02;
import mybatis.domain.User;
import mybatis.mapper.Mapper08;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

//mapper08.xml, SqlMapConfig.xml
public class Main08 {	
	public static void main(String[] args) throws Exception{		
		Reader reader = Resources.getResourceAsReader("config/SqlMapConfig.xml");		
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);		
		SqlSession sqlSession = sqlSessionFactory.openSession();
		
		Mapper08 mapper = sqlSession.getMapper(Mapper08.class);
		
		Search02 search = new Search02();					
				
		out.println("[getUsers-1]");
		search.setUserName(new String[]{"한아름","고석한"});
		for(User user: mapper.getUsers(search)) 
			out.println(user);
		
		out.println("[getUsers-2]");
		search.setUserName(null);
		search.setAge(Arrays.asList(25,30));
		for(User user: mapper.getUsers(search)) 
			out.println(user);
		
		out.println("[getUsers-3]");
		search.setUserName(new String[]{"한아름","고석한"});
		search.setAge(Arrays.asList(25,30));
		for(User user: mapper.getUsers(search)) 
			out.println(user);
		
		out.println("[getUsers02]");
		for(User user: mapper.getUsers02(new String[]{"한아름","고석한"})) 
			out.println(user);
		
		out.println("[getUsers03]");
		for(User user: mapper.getUsers03(Arrays.asList(25,30))) 
			out.println(user);
	}
}